package com.example.jl.bethinner.activity;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.example.jl.bethinner.R;

import java.util.regex.Pattern;


public class ZzbdsActivity extends ActionBarActivity {

    private EditText edit_text;
    private TextView name;
    private TextView ip;
    private TextView transform;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zzbds);
        edit_text = (EditText) findViewById(R.id.edit_text);
        name = (TextView) findViewById(R.id.name);
        ip = (TextView) findViewById(R.id.ip);
        transform = (TextView) findViewById(R.id.transform);

        transform.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DoTransfrom(edit_text.getText().toString());
            }
        });
    }

    private void DoTransfrom(String s) {
        String regEx = "@";
        String regEx2 = "/";
        Pattern pat = Pattern.compile(regEx);
        String[] rs = pat.split(s);
        name.setText(rs[0]);

        if (rs.length > 1) {
            Pattern pat2 = Pattern.compile(regEx2);
            String[] rs2 = pat2.split(rs[1]);
            ip.setText(rs2[0]);
        }

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_zzbds, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {


            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
